package com.sy.core.exception;

import com.sy.core.base.controller.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.concurrent.atomic.AtomicLong;

/**
 * 异常基类
 *
 * @author chengl
 * @version 1.0
 * @Date 2011-8-17
 */
public abstract class BaseException extends Exception {


    private static final long serialVersionUID = -4305232971206313027L;

    private static AtomicLong atomicLong = new AtomicLong(System.currentTimeMillis());
    private String id;

    public BaseException() {
        super();
        setId();
    }

    public BaseException(final String message) {
        super(message);

        setId();
    }

    public BaseException(final String message, final Throwable cause) {
        super(message, cause);
        setId();
    }

    private void setId() {
        long nid = atomicLong.incrementAndGet();
        id = Long.toString(nid, 26);
    }

    public abstract String getErrorTitle();

    public abstract String getErrorDescription();


    public Integer getLineNumber() {
        return -1;
    }

    public String getId() {
        return id;
    }

    public static String toString(Exception e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        return sw.toString();
    }

}